package client.comm.baoding.fragment

import android.content.Intent
import android.text.TextUtils
import androidx.lifecycle.Observer
import client.comm.baoding.R
import client.comm.baoding.api.bean.UserInfo
import client.comm.baoding.databinding.FragmentZz2OneBinding
import client.comm.baoding.ui.ZcJlActivity
import client.comm.baoding.ui.vm.Zz2ViewModel
import client.comm.commlib.base.BaseFragment
import client.comm.commlib.dialog.ValidatePwdDialog
import client.comm.commlib.toast.toast
import client.comm.commlib.utils.StoreUtil

class Zz2OneFragment : BaseFragment<FragmentZz2OneBinding, Zz2ViewModel>() {

    override fun getViewId(): Int {
        return R.layout.fragment_zz2_one
    }

    override fun initViewModel(): Zz2ViewModel = createViewModel()

    override fun initWidget() {
        binding?.apply {
            event = this@Zz2OneFragment
            vm = viewModel
            StoreUtil.getBean<UserInfo>(requireContext())?.let {
                viewModel.userInfo.value = it
                inconme = it.income.toString()
            }
        }
//        viewModel.call.observe(this, Observer {
//            it?.apply {
//                if (isSuccess) {
//                    toast("操作成功")
//                    startActivity(Intent(requireContext(), ZcJlActivity::class.java).apply {
//                        putExtra("index", 1)
//                    })
//                    requireActivity().finish()
//                } else {
//                    toast(it.message)
//                }
//            }
//        })
    }

    override fun initData() {
        arguments?.let {
            var fragmentId = it.getInt("fragmentID")
//            toast("$fragmentId")
//            binding.tag = "$fragmentId"

        }
    }


    fun ok() {
        if (TextUtils.isEmpty(viewModel.zzNum.value) || viewModel.username.value.isNullOrEmpty()) {
            toast("所有不能为空")
            return
        }
        ValidatePwdDialog(requireContext()).apply {
            title = "需要验证支付密码"
            ok = {
                viewModel.ok(it)
            }
        }.show()
    }


}